package ltd.smallwang.client.task.dto;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
 * @author justd
 * @description 功能描述
 * @since 2024-04-25 00:48
 **/
@Data
public class TaskQry {
  @Min(0)
  @Max(1)
  private Integer starFlag;

  @Min(0)
  @Max(1)
  private Integer completeFlag;
  /**
   * example: 2000-10-31T01:30:00.000-05:00 2024-03-31T01:30:00.000Z
   * DateTimeFormat.ISO.DATE_TIME)
   */
  @Size(max = 32)
  private String startTimeStr;

  @Size(max = 32)
  private String endTimeStr;

  public LocalDateTime getStartTime() {
    try {
      return LocalDateTime.parse(startTimeStr, DateTimeFormatter.ISO_DATE_TIME);
    } catch (DateTimeParseException exception) {
      return null;
    }
  }

  public LocalDateTime getEndTime() {
    try {
      return LocalDateTime.parse(endTimeStr, DateTimeFormatter.ISO_DATE_TIME);
    } catch (DateTimeParseException exception) {
      return null;
    }
  }
}
